package org.lyq.erp.auth.department.service;

import java.util.List;
import javax.annotation.Resource;
import org.lyq.erp.auth.department.mapper.DepartmentMapper;
import org.lyq.erp.auth.department.pojo.Department;
import org.lyq.erp.auth.employee.mapper.EmployeeMapper;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

@Service
public class DepartmentServiceImpl implements DepartmentService {

	@Resource
	private DepartmentMapper departmentMapper;

	@Resource
	private EmployeeMapper employeeMapper;

	public List<Department> list() {
		return this.departmentMapper.selectAllDepartmentList();
	}

	@Transactional
	public void insert(Department department) {
		department.setUpdatetime(Long.valueOf(System.currentTimeMillis()));
		department.setCreatetime(Long.valueOf(System.currentTimeMillis()));
		this.departmentMapper.insertSelective(department);
	}

	@Transactional
	public void update(Department department) {
		department.setUpdatetime(Long.valueOf(System.currentTimeMillis()));
		this.departmentMapper.updateByPrimaryKeySelective(department);
	}

	public Department selectByPrimaryKey(Integer depUuid) {
		return this.departmentMapper.selectByPrimaryKey(depUuid);
	}

	@Transactional
	public void delete(Integer depUuid) {
		
		this.departmentMapper.delete(depUuid);
		this.employeeMapper.deleteAllEmployeeByDepUuid(depUuid);
	}
}
